package test.top1.com.atguigu.utils;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: KeyWordUtil
 * Package: test.top1.com.atguigu.utils
 * Description:
 *
 * @Author ChenJun(有志男青年)
 * @Create 2023/5/5 21:00
 * @Version 1.0
 */
public class KeyWordUtil {

    public static List<String> splitKeyWord(String keyWord) throws IOException {

        //创建集合
        ArrayList<String> list = new ArrayList<>();

        //创建分词对象
        IKSegmenter ikSegmenter = new IKSegmenter(new StringReader(keyWord), false);

        Lexeme next = ikSegmenter.next();

        //遍历切出的分词
        while (next  != null){

            String lexemeText = next.getLexemeText();
            list.add(lexemeText);
            next = ikSegmenter.next();
        }

        //返回结果
        return list;
    }

    public static void main(String[] args) throws IOException {
        System.out.println(splitKeyWord("尚硅谷大数据上海校区"));
    }
}
